<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>数据上报记录</title>
    <#include "/common/resource.ftl">
</head>
<body >
   <div class="ui-operation" style="margin-top: 8px;">
       <div class="ui-buttons">
   		 <div class="layui-btn-group tools">
            <button class="layui-btn layui-btn-normal exportButton" p="url:'${params.contextPath}/view/icip/datareport/datareport_task_detail.htm',title:'数据上报任务详情',width:'800px',height:'90%'">
				<i class="fa fa-download"></i>导出
			</button>
         </div>  
       </div>
   </div>
   <div class="ui-content" style="padding-left: 10px;padding-right:10px;">
   </div> 
   <table id="datagrid-template" options="url:'${params.contextPath}/web/report/list.json?taskid=${params.id}&templateid=${params.templateid}'" style="display: none;">
        <thead>
            <tr>
            	<th data-options="field:'orgName',width:60">上报单位</th>
                <th data-options="field:'createTimeStr',width:60">上报时间</th>
            </tr>
        </thead>
    </table>  
</body>
<script>
//格式化模板自定义属性值
function formatValue(value,row){
	var val = row.data.json[this.field];
	return val;
}
//根据数据上报模板渲染表格
function renderDatagrid(templateid){
	$(".ui-content").empty();// 移除原表格
	var datagrid = $("#datagrid-template").clone();
	datagrid.attr("id","datagrid-custom").show();
	datagrid.attr("")
	$(".ui-content").append(datagrid);
	// 获取表格显示列
	$.ajaxRequest({
		url: '${params.contextPath}/web/reportTemplate/query.json',
        data: {id: templateid},
        success: function (data) {
        	var inputList = data.data.inputList;
        	var datagridHeader = $("#datagrid-custom").find('tr:eq(0)');
            if(inputList){
            	var field = null;
            	for(var i=0;i<inputList.length;i++){
            		var input = inputList[i];
            		field = $('<th data-options="field:\''+input.enName+'\',width:60,formatter:formatValue">'+input.chName+'</th>');
            		datagridHeader.append(field);
            	}
            }
            DataGrid.renderId="#datagrid-custom";
        	DataGrid.init();
        }
    });
}

$(document).ready(function(){
	renderDatagrid('${params.templateid}');
	$(".exportButton").click(function(){
		var url = "${params.contextPath}/web/report/export.json?taskid=${params.id}&templateid=${params.templateid}";
		window.location.href = url;
	});
});
</script>
</html>
